/*
 * queue
 *
 *  Created on: May 3, 2011
 *      Author: tvale, dmourao
 */

#ifndef QUEUE_H_
#define QUEUE_H_

#include "common.h"
#include <stdio.h>

/*
 * Queue states.
 *      EMPTY:       self explainable;
 *      WAITING_ACK: empty but waiting for inquiry result;
 *      NOT_EMPTY:   self explainable.
 *      FINISHED:    client terminated.
 */
typedef enum queue_state {
  QUEUE_EMPTY       = 0,
  QUEUE_WAITING_ACK = 1,
  QUEUE_NOT_EMPTY   = 2,
  QUEUE_FINISHED    = 3
} queue_state_t;

/*
 * Opaque pointer for information hiding.
 */
typedef struct queue* queue_ptr;

/*
 * Operations.
 *      create:    returns a new, initialized queue;
 *      destroy:   releases all resources of a queue;
 *      remove:    removes and returns the queue's head;
 *      peek:      returns a pointer to the queue's head;
 *      add:       adds an element to the queue;
 *      set_state: sets the queue's state;
 *      get_state: returns the queue's state;
 */
queue_ptr     queue_create();
void          queue_destroy(queue_ptr);
msg_t         queue_remove(queue_ptr);
msg_t*        queue_peek(queue_ptr);
void          queue_add(queue_ptr, msg_t);
void          queue_set_state(queue_ptr, queue_state_t);
queue_state_t queue_get_state(queue_ptr);
void          queue_print(queue_ptr, FILE*);

#endif /* QUEUE_H_ */
